//@ts-ignore,引入请求函数
import request from "@/utils/request.ts";


/**
 * 权限管理模块
*/

//@ts-ignore,引入类型约束文件
import { response_userInfoList } from "./type.ts";

enum API {
    //用户管理部分
    USERLIST = "/admin/acl/user",  //管理用户列表
    SAVEUSER = "/admin/acl/user/save",  //添加管理用户
    UPDATEUSER = "/admin/acl/user/update",  //修改管理用户
    DELETEUSER = "/admin/acl/user/remove",  //删除一个管理用户
    USERROLELIST = "/admin/acl/user/toAssign",  //根据用户获取角色数据
    DISTRIBUTEROLE = "/admin/acl/user/doAssignRole",  //根据用户id分配角色
    DELETEUSERLIST = "/admin/acl/user/batchRemove",  //批量删除用户
    //角色管理部分
    ROLELIST = "/admin/acl/role",  //所有角色信息列表
    ADDROLE = "/admin/acl/role/save",  //添加一个新角色
    UPDATEROLE = "/admin/acl/role/update",  //修改一个角色
    DELETEROLE = "/admin/acl/role/remove",  //删除一个角色
    FINDROLEPERMISSIONINFO = "/admin/acl/permission/toAssign",  //根据角色id获取权限信息
    DISTRIBUTEPERMISSIONFORROLE = "/admin/acl/permission/doAssignAcl",  //给角色分配权限
}

//获取管理用户分页列表
export const reqUserList = (page:number,limit:number,queryParams:any) => {
    return request<any,response_userInfoList>({
        url:API.USERLIST +"/"+ page +"/"+ limit,
        method:"get",
        params:queryParams
    })
}

//新增管理用户
export const reqAddUser = (newUserInfo:any) => {
    return request<any,any>({
        url:API.SAVEUSER,
        method:"post",
        data:newUserInfo
    })
}

//修改管理用户
export const reqUpdateUser = (updateUserInfo:any) => {
    return request<any,any>({
        url:API.UPDATEUSER,
        method:"put",
        data:updateUserInfo
    })
}

//删除一个管理用户
export const reqDeleteUser = (userId:number) => {
    return request<any,any>({
        url:API.DELETEUSER +"/"+ userId,
        method:"delete"
    })
}

//根据用户id获取角色数据
export const reqRoleListByUserId = (userId:number) => {
    return request<any,any>({
        url:API.USERROLELIST +"/"+ userId,
        method:"get"
    })
}

//根据用户分配角色
export const reqDistributeRoleByUserId = (userId:number,roleIdList:number[]) => {
    return request<any,any>({
        url:API.DISTRIBUTEROLE,
        method:"post",
        data:{
            userId,
            roleIdList
        }
    })
}

//批量删除用户
export const reqDeleteUserList = (userIdList:number[]) => {
    return request<any,any>({
        url:API.DELETEUSERLIST,
        method:"delete",
        data:userIdList
    })
}

/**
 * 角色管理部分
*/

//获取所有角色信息
export const reqRoleInfo = (page:number,limit:number,queryParams:any) => {
    return request<any,any>({
        url:API.ROLELIST +"/"+ page +"/"+ limit,
        method:"get",
        params:queryParams
    })
}

//新添加一个角色
export const reqAddRole = (roleInfo:any) => {
    return request<any,any>({
        url:API.ADDROLE,
        method:"post",
        data:roleInfo
    })
}

//修改一个角色
export const reqUpdateRole = (roleInfo:any) => {
    return request<any,any>({
        url:API.UPDATEROLE,
        method:"put",
        data:roleInfo
    })
}

//删除一个角色
export const reqDeleteRole = (roleId:number) => {
    return request<any,any>({
        url:API.DELETEROLE +"/"+ roleId,
        method:"delete"
    })
}

//获取当前角色权限信息
export const reqRolePermissionInfo = (roleId:number) => {
    return request<any,any>({
        url:API.FINDROLEPERMISSIONINFO +"/"+ roleId,
        method:"get"
    })
}

//给角色分配权限
export const reqDistributePermission = (permissionIds:number[],roleId:number) => {
    return request<any,any>({
        url:API.DISTRIBUTEPERMISSIONFORROLE,
        method:"post",
        data:{
            permissionIdList:permissionIds,
            roleId
        }
    })
}


/**
 * 菜单管理模块
*/

//获取菜单
export const reqMenuList = () => {
    return request<any,any>({
        url:"/admin/acl/permission",
        method:"get"
    })
}

//给某一级新增一个菜单
export const reqAddMenu = (menuInfo:any) => {
    return request<any,any>({
        url:"/admin/acl/permission/save",
        method:"post",
        data:menuInfo
    })
}

//修改一个菜单
export const reqUpdateMenu = (menuInfo:any) => {
    return request<any,any>({
        url:"/admin/acl/permission/update",
        method:"put",
        data:menuInfo
    })
}

//删除一个菜单
export const reqDelMenu = (menuId:number) => {
    return request<any,any>({
        url:"/admin/acl/permission/remove" +"/"+ menuId,
        method:"delete"
    })
}